package com.activity.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.activity.App;
import com.activity.bean.ClassBean;
import com.donkingliang.groupedadapter.holder.BaseViewHolder;
import com.example.apple.ddhr_new.R;
import com.example.apple.ddhr_new.adapter.BaseAdapter;

import org.apache.commons.lang3.StringUtils;

import androidx.annotation.NonNull;
import butterknife.BindView;

public class AttendanceSetAdapter extends BaseAdapter<ClassBean> {

    public AttanceSetListener attanceSetListener;


    public AttendanceSetAdapter(Context context) {
        super(context);
    }



    @Override
    public boolean hasHeader(int groupPosition) {
        return true;
    }

    @Override
    public BaseViewHolder<ClassBean> getViewHolder(int viewType, View view) {
        if(viewType==TYPE_CHILD)
        return new AttendanceViewHolder(view);

        return null;
    }

    @Override
    public int getHeaderLayout(int viewType) {
        return R.layout.header_attence_set;
    }

    @Override
    public int getChildLayout(int viewType) {
        return R.layout.item_attence_set_cell;
    }

    @Override
    public void onBindChildViewHolder(com.donkingliang.groupedadapter.holder.BaseViewHolder holder, int groupPosition, int childPosition) {
        super.onBindChildViewHolder(holder, groupPosition, childPosition);
        AttendanceViewHolder attendanceViewHolder = (AttendanceViewHolder) holder;
        attendanceViewHolder.ivDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (attanceSetListener != null) {
                    attanceSetListener.deleteClick(childPosition);
                }
            }
        });
        attendanceViewHolder.tvUpdate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (attanceSetListener != null) {
                    attanceSetListener.updateClick(childPosition);
                }
            }
        });

    }

    @Override
    public void onBindHeaderViewHolder(com.donkingliang.groupedadapter.holder.BaseViewHolder holder, int groupPosition) {


        TextView tv_people = holder.itemView.findViewById(R.id.tv_people);
        TextView tv_people1 = holder.itemView.findViewById(R.id.tv_people1);
        tv_people.setText("全公司"+App.getInstance().userstoreinfoBean.getStoremembernum() +"人");
        tv_people1.setText("全公司"+App.getInstance().userstoreinfoBean.getStoremembernum() +"人");
        holder.itemView.findViewById(R.id.l_daka).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (attanceSetListener != null) {
                    attanceSetListener.clockClick();
                }
            }
        });
        holder.itemView.findViewById(R.id.l_kaoqin).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (attanceSetListener != null) {
                    attanceSetListener.sheetClick();
                }
            }
        });
        holder.itemView.findViewById(R.id.iv_add).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (attanceSetListener != null) {
                    attanceSetListener.addClick();
                }
            }
        });
        holder.itemView.findViewById(R.id.l_waichu).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (attanceSetListener != null) {
                    attanceSetListener.waiChuClick();
                }
            }
        });
        holder.itemView.findViewById(R.id.l_jiaban).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (attanceSetListener != null) {
                    attanceSetListener.jiabanClick();
                }
            }
        });
    }

    public interface AttanceSetListener {
        public void clockClick();

        public void sheetClick();

        public void addClick();
        public void waiChuClick();
        public void jiabanClick();
        public  void deleteClick(int childPosition);
        public  void updateClick(int childPosition);
    }

    public class AttendanceViewHolder extends BaseViewHolder<ClassBean> {
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.iv_delete)
        ImageView ivDelete;
        @BindView(R.id.tv_member)
        TextView tvMember;
        @BindView(R.id.tv_class)
        TextView tvClass;
        @BindView(R.id.tv_cla)
        TextView tvCla;
        @BindView(R.id.tv_address)
        TextView tvAddress;
        @BindView(R.id.tv_update)
        TextView tvUpdate;
        public AttendanceViewHolder(@NonNull View itemView) {
            super(itemView);
        }

        @Override
        public void setData(ClassBean data) {
            tvName.setText(data.getAttendancegroupname());
            tvMember.setText("成员:"+StringUtils.split(data.getAttendancegroupmembers(),",").length+"人");

            tvClass.setText(data.getClassDay());

            tvCla.setText(data.getClassSpan());
            tvAddress.setText(data.getClassAddress());


        }


    }


}
